package com.thesis.object;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

/**
 * ListTable class
 * 
 * save all tables in list table
 * 
 * @author NgocTuyen
 *
 */
public class ListTable {
	//array list save all tables
	private ArrayList<Table> listTable;
	
	/**
	 * Constructor function
	 * 
	 * Constructor
	 * 
	 * @access public 
	 * 
	 * @param null
	 * 
	 * @return null
	 * 
	 */
	public ListTable(){
		listTable = new ArrayList<Table>();
	}
	
	/**
	 * addTableByJson function
	 * 
	 * add all table into list table
	 * 
	 * @access public
	 * 
	 * @param listJson list of all table
	 * 
	 * @retun void
	 */
	public void addTableByJson(JSONArray listJson){
		for (int i = 0; i < listJson.length(); i++) {
			try {
				addTable((JSONObject)(listJson.get(i)));
			} catch (JSONException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		Log.d("LISTTABLE" , ""+listTable.size());
	}
	
	/**
	 * addTable function
	 * 
	 * add a table in to listTable
	 * 
	 * @access private
	 * 
	 * @param jsonObj json of one table
	 * 
	 * @return void
	 */
	private void addTable(JSONObject jsonObj){
		try {
			Table table = new Table(jsonObj.getInt("_id"), jsonObj.getString("name"), jsonObj.getInt("number"), jsonObj.getInt("manager_id"), jsonObj.getString("first_name"), jsonObj.getString("last_name"), jsonObj.getInt("waiter_id"), jsonObj.getInt("status_id"), jsonObj.getString("status"), jsonObj.getInt("extra_table"), jsonObj.getInt("booking_status_id"), jsonObj.getString("booking_status"), jsonObj.getString("booking_time"), jsonObj.getString("booking_description"), jsonObj.getString("desciption"), jsonObj.getString("image"));
			listTable.add(table);
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	/**
	 * getListTable function
	 * 
	 * get list all tables in restaurant
	 * 
	 * @access public
	 * 
	 * @param null
	 * 
	 * @return ArrayList<Table>
	 *  + list of all tables
	 */
	public ArrayList<Table> getListTable(){
		return listTable;
	}
}
